slices <- c(37,276,3,15,3,34,3)
names <- c("happy", "good", "angry", "sad", "fear", "boring", "suprise")
#png("r-graph-sample.png")
barplot(beside=TRUE,
slices,#纵轴取值
names.arg=names,#边框名字
border="black",#边框颜色
col=c("purple","green3","blue", "red"),#框内线条颜色
density = c(10,12.5,17.5),#框内线条密度
angle = c(45,60,120),#框内线条倾斜角度
width = c(2.5,2.5,2.5),#边框宽度
space = c(0.3,0.3,0.3),#边框间距
ylim=c(0,300),#纵轴取值范围
)
title(xlab="Emotion Type")#横轴名字
title(ylab="Emotion Score")#纵轴名字
lbls <- round(slices/sum(slices)*100)
lbls <- paste(lbls,"%",sep="")# ad % to labels
lbls <- paste(names, lbls)# add percents to labels
#图例
legend("topright",lbls,
fill=c("purple","green3","blue","red"),
density = c(7.5,12.5,17.5,22.5),
angle = c(45,60,120,135),)